package com.cxg.fairy.ec.main.personal.favor;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cxg.fairy.ec.main.personal.address.AddressItemFields;
import com.cxg.fairy.ec.main.personal.address.AddressItemType;
import com.cxg.fairy.ui.recycler.DataConverter;
import com.cxg.fairy.ui.recycler.MultipleFields;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;

import java.math.BigDecimal;
import java.util.ArrayList;

/**
 * Created by Administrator on 2018/3/8.
 */

public class FavorDataConverter extends DataConverter {

    @Override
    public ArrayList<MultipleItemEntity> convert() {

        final JSONArray array = JSON.parseObject(getJsonData()).getJSONArray("data");
        if (array == null)
            return null;
        final int size = array.size();
        for (int i = 0; i < size; i++) {

            final JSONObject data = array.getJSONObject(i);
            final int id = data.getInteger("favoriteId");
            final int goods_id = data.getInteger("goodsId");
            final String goods_name = data.getString("name");
            final String goods_unit = data.getString("unit");
            final BigDecimal goods_price = data.getBigDecimal("price");
            final String img_url = data.getString("pic");
            final int cartQuantity = 100;
            final int spanSize = 30;

            final MultipleItemEntity entity = MultipleItemEntity.builder()
                    .setItemType(FavorItemType.FAVOR_ITEM)
                    .setField(FavorItemFields.ID, id)
                    .setField(FavorItemFields.GOODS_ID,goods_id)
                    .setField(FavorItemFields.GOODS_NAME, goods_name)
                    .setField(FavorItemFields.GOODS_UNIT, goods_unit)
                    .setField(FavorItemFields.GOODS_PRICE, goods_price)
                    .setField(FavorItemFields.IMAGE_URL, img_url)
                    .setField(FavorItemFields.GOODS_COUNT, cartQuantity)
                    .setField(FavorItemFields.SPAN_SIZE, spanSize)
                    .build();
            ENTITIES.add(entity);
        }

        return ENTITIES;
    }

    @Override
    public MultipleItemEntity convertHeader() {
        return null;
    }
}
